import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import './index.scss'

export default class Index extends Component {

  config = {
    navigationBarTitleText: '首页'
  }

  constructor(props) {
    super(props);
    this.state = { date: new Date() }
  }

  componentWillMount() { }

  componentDidMount() {
    this.timerId = setInterval(
      () => this.tick(),
      1000);
  }

  componentWillUnmount() {
    clearInterval(this.timerId)
  }

  componentDidShow() { }

  componentDidHide() { }

  render() {
    return (
      <View className='index'>
        <Text>现在时间是：{this.state.date.toLocaleTimeString()}</Text>
      </View>
    )
  }

  tick() {
    this.setState({ date: new Date() });
  }
}

